namespace Slaks.Graphs.Algorithms.ExperimentalDistances
{
	public class MCSlimited
	{
		/// <summary>
		/// MCSlimited
		/// </summary>
		/// <param name="one"></param>
		/// <param name="two"></param>
		/// <returns></returns>
		public static double DistMCS4VertexEdgeCountLimited(Graph one, Graph two)
		{
			double result;

			Graph maxCommonSubgraph = (MaxCommonSubGraphVertexEdgeCount.GetMCS(one, two));
			double mcsEdgeCount = maxCommonSubgraph.GetEdgeCount();
			double mcsVertexCount = maxCommonSubgraph.GetVertexCount();
			double mcsCommonGraphSize = mcsEdgeCount + mcsVertexCount;

			double graphSizeOneVertexCount = one.GetVertexCount();
			double graphSizeTwoVertexCount = two.GetVertexCount();

			double graphSizeOneEdgeCount = one.GetEdgeCount();
			double graphSizeTwoEdgeCount = two.GetEdgeCount();

			double limitedSizeOne =
				(graphSizeOneEdgeCount > graphSizeOneVertexCount) ? graphSizeOneVertexCount*2 : graphSizeOneVertexCount + graphSizeOneEdgeCount;
			double limitedSizeTwo =
				(graphSizeTwoEdgeCount > graphSizeTwoVertexCount) ? graphSizeTwoVertexCount*2 : graphSizeTwoVertexCount + graphSizeTwoEdgeCount;

			if (limitedSizeOne > limitedSizeTwo)
			{
				result = 1 - mcsCommonGraphSize/limitedSizeOne;
			}
			else
			{
				result = 1 - mcsCommonGraphSize/limitedSizeTwo;
			}

			if (result < 0) result = 0;

			return result;
		}

		/// <summary>
		/// MCSlimited
		/// </summary>
		/// <param name="one"></param>
		/// <param name="two"></param>
		/// <returns></returns>
		public static double DistMCS4VertexEdgeFrequencyLimited(Graph one, Graph two)
		{
			double result;

			Graph maxCommonSubgraph = (MaxCommonSubGraphVertexEdgeFrequency.GetMCS(one, two));
			double mcsEdgeFrequency = maxCommonSubgraph.GetEdgeFrequency();
			double mcsVertexFrequency = maxCommonSubgraph.GetVertexFrequency();
			double mcsCommonGraphSize = mcsEdgeFrequency + mcsVertexFrequency;

			double graphSizeOneVertexFrequency = one.GetVertexFrequency();
			double graphSizeTwoVertexFrequency = two.GetVertexFrequency();

			double graphSizeOneEdgeFrequency = one.GetEdgeFrequency();
			double graphSizeTwoEdgeFrequency = two.GetEdgeFrequency();

			double limitedSizeOne =
				(graphSizeOneEdgeFrequency > graphSizeOneVertexFrequency) ? graphSizeOneVertexFrequency*2 : graphSizeOneVertexFrequency + graphSizeOneEdgeFrequency;
			double limitedSizeTwo =
				(graphSizeTwoEdgeFrequency > graphSizeTwoVertexFrequency) ? graphSizeTwoVertexFrequency*2 : graphSizeTwoVertexFrequency + graphSizeTwoEdgeFrequency;

			if (limitedSizeOne > limitedSizeTwo)
			{
				result = 1 - mcsCommonGraphSize/limitedSizeOne;
			}
			else
			{
				result = 1 - mcsCommonGraphSize/limitedSizeTwo;
			}

			if (result < 0) result = 0;

			return result;
		}


	}
}